//
//  ZJWacthDetailViewController.swift
//  mini
//
//  Created by Mac on 2017/5/22.
//  Copyright © 2017年 Mac. All rights reserved.
//

import UIKit


class ZJWacthDetailViewController: UIViewController {
    
    var tableView:UITableView?
    
    var resultArr:[ZJRunModel] = {
        
        let arr:NSArray = NSArray()
        
        return arr as! [ZJRunModel]
        
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        setData()
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func setUI() {
        
        title = "健身记录"
        view.backgroundColor = kGlobelBgColor
        tableView =  UITableView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight-(navigationController?.navigationBar.height)!))
        tableView?.delegate = self
        tableView?.dataSource = self
        tableView?.backgroundColor = kGlobelBgColor
        view.addSubview(tableView!)
        tableView?.tableFooterView = UIView()
        
    }
    
    func setData()  {
        
        let tempParam:NSDictionary = ["equip_id":"c92dc60301a0",
                                      "page_num":"1"]
        let hsha:ZJRunModel = ZJRunModel()
        let requestHandleer: requestRecource = requestRecource(path: "interface/gxy/member_stepcounter_list.aspx", params:tempParam as! [String: String], parser: hsha.getRunModelData)
        YCHud.show()
        requestHandleer.request(callback: { (result) in
            YCHud.dismiss()
            self.resultArr = result!
            self.tableView?.reloadData()
        }) { (error) in
            YCHud.dismiss()
            YCHud.showError()
        }
        
    }

    

}

extension ZJWacthDetailViewController:UITableViewDelegate,UITableViewDataSource{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return resultArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellID = "cellID"
        
        var  cell = tableView.dequeueReusableCell(withIdentifier: cellID)
        
        
        if cell == nil {
            cell = UITableViewCell.init(style: .subtitle, reuseIdentifier: cellID)
        }
        
        let model:ZJRunModel = resultArr[indexPath.row] 
        
        cell?.textLabel?.text = model.distance! + "/" + model.steps! + "/" + model.calories!
        cell?.textLabel?.textAlignment = NSTextAlignment.left
        cell?.detailTextLabel?.text = model.measuretime
        cell?.detailTextLabel?.font = UIFont.systemFont(ofSize: 10)
        return cell!
        
        
        
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        let headView:ZJHeadView = ZJHeadView.headerViewWithTableView(tableView: tableView)
        
        headView.headerStr = "距离/步数/卡路里"
        
        return headView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 43
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    
}
